package com.gai.emp.web.controller;

import com.alibaba.druid.util.StringUtils;
import com.gai.emp.entity.Emp;
import com.gai.emp.services.EmpServices;
import com.gai.emp.services.impl.EmpServicesImpl;
import com.github.pagehelper.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getEmp")
public class EmpController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String pageIndex = request.getParameter("pageIndex");
        if (StringUtils.isEmpty(pageIndex)){
            pageIndex="1";
        }
        String pageSize = request.getParameter("pageSize");
        if (StringUtils.isEmpty(pageSize)){
            pageSize="5";
        }

        EmpServices es = new EmpServicesImpl();
        PageInfo<Emp> all = es.getAll(Integer.valueOf(pageIndex), Integer.valueOf(pageSize));

        response.getWriter().println(all);
    }
}